//util工具类：
const hexFromBuffer = buffer => {
  var hexArr = Array.prototype.map.call(
    new Uint8Array(buffer),
    function (bit) {
      return ('00' + bit.toString(16)).slice(-2)
    }
  )
  return hexArr.join('');
}

const bufferFromHex = hex => {
  var typedArray = new Uint8Array(hex.match(/[\da-f]{2}/gi).map(function (h) {
    return parseInt(h, 16)
  }))
  return typedArray.buffer
}

const recordLog = (typeVal,desc) =>{
  let app = getApp();
  if (app.globalData._that && typeof (app.globalData._that.recordBlueConnectError) == "function"){
    console.log("记录错误日志.....",typeVal,desc);
    app.globalData._that.recordBlueConnectError(typeVal,desc);
  }
}

module.exports = {
  hexFromBuffer: hexFromBuffer,
  bufferFromHex: bufferFromHex,
  recordLog: recordLog 
}
